<!DOCTYPE html
    PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>
    <title>借阅面板</title>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

    <script src="../../scripts/boot.js" type="text/javascript"></script>


    <style type="text/css">
        html,
        body {
            padding: 0;
            margin: 0;
            border: 0;
            height: 100%;
            overflow: hidden;
        }
    </style>
</head>

<body>

    <form id="borrowinfoadd" method="post">
        <div style="padding-left:11px;padding-bottom:5px;">
            <table style="table-layout:fixed;">
                <tr>
                    <td style="width:80px;">借阅号：</td>
                    <td style="width:150px;">
                        <input name="borrowId" class="mini-textbox" allowInput="false" />
                    </td>
                    <td style="width:80px;">图书名称：</td>
                    <td style="width:150px;">
                        <input name="bookId" class="mini-combobox" url="../../bookinfolistaction?method=queryAll"
                            textField="bookName" valueField="bookId" required="true" emptyText="请选择借阅图书名称" />
                    </td>
                </tr>
                <tr>
                    <td>借阅人：</td>
                    <td>
                        <input name="borrower" class="mini-textbox" required="true" />
                    </td>
                    <td>联系电话：</td>
                    <td>
                        <input name="phone" class="mini-textbox" required="true" onvalidation="onPhoneValidation"/>
                    </td>
                </tr>

                <tr>
                    <td>借阅时间：</td>
                    <td>
                        <input name="borrowTime" class="mini-datepicker" style="width:150px;" nullValue="null"
                            required="true" format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showTime="true"
                            showOkButton="true" showClearButton="false" />

                    </td>
                    <td>归还时间：</td>
                    <td>
                        <input name="returnTime" class="mini-datepicker" style="width:150px;" nullValue="null"
                            format="yyyy-MM-dd H:mm:ss" timeFormat="H:mm:ss" showTime="true" showOkButton="true"
                            showClearButton="false" />
                    </td>
                </tr>

            </table>
        </div>
        <div style="text-align:center;padding:10px;">
            <a class="mini-button" onclick="onOk" style="width:60px;margin-right:20px;">确定</a>
            <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>
        </div>
    </form>
    <script type="text/javascript">
        mini.parse();

        var form = new mini.Form("borrowinfoadd");
        // 加载借阅号
        $.ajax({
            url: "../../borrowinfolistaction?method=queryId",
            cache: false,
            success: function (result) {
                mini.getByName("borrowId").setValue(result);
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert(jqXHR.responseText);
                CloseWindow();
            }
        });
        // 加载默认借阅日期
        var nowDate = mini.formatDate(new Date(), "yyyy-MM-dd HH:mm:ss");
        mini.getByName("borrowTime").setValue(nowDate);
        // 电话号码校验
        function onPhoneValidation(e) {
            if (e.isValid) {
                var pattern = /^(13[0-9]|14[01456879]|15[0-35-9]|16[2567]|17[0-8]|18[0-9]|19[0-35-9])\d{8}$/;
                if (pattern.test(e.value) == false) {
                    e.isValid = false;
                }
            }
        }
        // 保存表单信息
        function SaveData() {
            var o = form.getData();

            form.validate();
            if (form.isValid() == false) return;

            var json = mini.encode(o);
            $.ajax({
                url: "../../borrowinfoaddaction",
                type: 'post',
                data: { data: json },
                cache: false,
                success: function (result) {
                    var res = mini.decode(result);
                    if (res.code == 1) {
                        CloseWindow("save");
                    } else {
                        mini.alert(res.msg,"操作失败",Window.CloseOwnerWindow);
                    }

                },
                error: function (jqXHR, textStatus, errorThrown) {
                    alert(jqXHR.responseText);
                    CloseWindow();
                }
            });
        }
        
        function SetData(data) {
            //跨页面传递的数据对象，克隆后才可以安全使用
            data = mini.clone(data);
            // 自动选中对应图书
            mini.getByName("bookId").setValue(data.id);

        }
        
        function GetData() {
            var o = form.getData();
            return o;
        }
        function CloseWindow(action) {
            if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
            else window.close();
        }
        function onOk(e) {
            SaveData();
        }
        function onCancel(e) {
            CloseWindow("cancel");
        }
    </script>
</body>

</html>